]>
Commit | Line | Data |
---|---|---|
1 | #region Using Statements | |
2 | using System; | |
3 | using System.Collections.Generic; | |
4 | using Microsoft.Xna.Framework; | |
5 | using Microsoft.Xna.Framework.Content; | |
6 | using Microsoft.Xna.Framework.Graphics; | |
7 | using Microsoft.Xna.Framework.Input; | |
8 | using Microsoft.Xna.Framework.Storage; | |
9 | using Microsoft.Xna.Framework.GamerServices; | |
10 | using SuperPolarity; | |
11 | #endregion | |
12 | ||
13 | namespace SuperPolarity | |
14 | { | |
15 | /// <summary> | |
16 | /// This is the main type for your game | |
17 | /// </summary> | |
18 | public class SuperPolarity : Game | |
19 | { | |
20 | public static GraphicsDeviceManager graphics; | |
21 | SpriteBatch spriteBatch; | |
22 | ||
23 | public SuperPolarity() | |
24 | : base() | |
25 | { | |
26 | SuperPolarity.graphics = new GraphicsDeviceManager(this); | |
27 | SuperPolarity.graphics.PreferMultiSampling = true; | |
28 | Content.RootDirectory = "Content"; | |
29 | ActorFactory.SetGame(this); | |
30 | } | |
31 | ||
32 | /// <summary> | |
33 | /// Allows the game to perform any initialization it needs to before starting to run. | |
34 | /// This is where it can query for any required services and load any non-graphic | |
35 | /// related content. Calling base.Initialize will enumerate through any components | |
36 | /// and initialize them as well. | |
37 | /// </summary> | |
38 | protected override void Initialize() | |
39 | { | |
40 | base.Initialize(); | |
41 | ||
42 | InputController.RegisterEventForButton("changePolarity", Buttons.A); | |
43 | InputController.RegisterEventForKey("changePolarity", Keys.Z); | |
44 | ||
45 | InputController.RegisterEventForButton("shoot", Buttons.X); | |
46 | InputController.RegisterEventForKey("shoot", Keys.X); | |
47 | } | |
48 | ||
49 | /// <summary> | |
50 | /// LoadContent will be called once per game and is the place to load | |
51 | /// all of your content. | |
52 | /// </summary> | |
53 | protected override void LoadContent() | |
54 | { | |
55 | // Create a new SpriteBatch, which can be used to draw textures. | |
56 | spriteBatch = new SpriteBatch(GraphicsDevice); | |
57 | ||
58 | Vector2 playerPosition = new Vector2(GraphicsDevice.Viewport.TitleSafeArea.X, GraphicsDevice.Viewport.TitleSafeArea.Y + GraphicsDevice.Viewport.TitleSafeArea.Height / 2); | |
59 | ||
60 | ActorFactory.CreateShip(Ship.Polarity.Positive, new Vector2(200, 200)); | |
61 | ActorFactory.CreateShip(Ship.Polarity.Negative, new Vector2(400, 200)); | |
62 | ActorFactory.CreateMainShip(playerPosition); | |
63 | } | |
64 | ||
65 | /// <summary> | |
66 | /// UnloadContent will be called once per game and is the place to unload | |
67 | /// all content. | |
68 | /// </summary> | |
69 | protected override void UnloadContent() | |
70 | { | |
71 | // TODO: Unload any non ContentManager content here | |
72 | } | |
73 | ||
74 | /// <summary> | |
75 | /// Allows the game to run logic such as updating the world, | |
76 | /// checking for collisions, gathering input, and playing audio. | |
77 | /// </summary> | |
78 | /// <param name="gameTime">Provides a snapshot of timing values.</param> | |
79 | protected override void Update(GameTime gameTime) | |
80 | { | |
81 | if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) | |
82 | Exit(); | |
83 | ||
84 | // TODO: Add your update logic here | |
85 | ||
86 | InputController.UpdateInput(); | |
87 | ActorManager.Update(gameTime); | |
88 | ||
89 | base.Update(gameTime); | |
90 | } | |
91 | ||
92 | /// <summary> | |
93 | /// This is called when the game should draw itself. | |
94 | /// </summary> | |
95 | /// <param name="gameTime">Provides a snapshot of timing values.</param> | |
96 | protected override void Draw(GameTime gameTime) | |
97 | { | |
98 | GraphicsDevice.Clear(Color.White); | |
99 | ||
100 | spriteBatch.Begin(); | |
101 | ||
102 | ActorManager.Draw(spriteBatch); | |
103 | ||
104 | spriteBatch.End(); | |
105 | ||
106 | base.Draw(gameTime); | |
107 | } | |
108 | } | |
109 | } |